/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

define(['adminapp', 'core/datatable'], function ($app) {
    $app.navactive('member');
    $app.listtable({
        'aoColumns'    : [
            $app.autono,
            {'mDataProp': 'id' },
            {'mDataProp': 'member' },
            {'mDataProp': 'record_time' },
            {'mDataProp': 'old_integral' },
            {'mDataProp': 'old_integral' },
            {'mDataProp': 'integral' },
            {'mDataProp': 'resume' }
        ],
        'aoColumnDefs' : [

            { 'bSearchable': false, 'bVisible': false, 'aTargets': [ 1, 2 ] },
            {
                'aTargets': [4], mData: 'old_integral', 'bSortable': true,
                'mRender' : function (data, type, full) {
                    return full['subtraction'] == 1 ? '<span class="badge badge-info">' + full['integral'] + '</span>' : '';
                }
            },
            {
                'aTargets': [5], mData: 'old_integral', 'bSortable': true,
                'mRender' : function (data, type, full) {
                    return full['subtraction'] == 0 ? '<span class="badge badge-warning">' + full['integral'] + '</span>' : '';
                }
            },
            {
                'aTargets': [6], mData: 'integral', 'bSortable': false,
                'mRender' : function (data, type, full) {
                    return full['subtraction'] == 1 ? full['old_integral'] + full['integral'] : full['old_integral'] - full['integral'];
                }
            },
            {
                'aTargets': [7], mData: 'resume', 'bSortable': false
            }
        ],
        'fnRowCallback': function (nRow, aData, iDisplayIndex) {
            var oSettings = this.fnSettings();
            $("td:eq(0)", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1);
            return nRow;
        }
    }, 'datatables-integral');
    return {};
});